package io.coding.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.coding.model.Bl_main_post;
import io.coding.service.PostService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;


/**
 * Created by Administrator on 2014/9/5.
 */
@Controller
public class PostController {

    private static final org.slf4j.Logger logger = LoggerFactory.getLogger(PostController.class);

    @Autowired
    private PostService postService;

    @RequestMapping(value = "/")
    public  String blogMain(HttpServletRequest req,Model model){
        String initPageNum = req.getParameter("pageNum");
        PageHelper.startPage(initPageNum!=null?Integer.parseInt(initPageNum):0, 5);
        PageInfo<Bl_main_post> page = new PageInfo(postService.findAll());
        model.addAttribute("page",page);
        return "/home";
    }

    @RequestMapping(value = "/blogcontent")
    public  String blogContent(Model model,long id){
        Bl_main_post bl_main_post = postService.findBlogById(id);
        if(bl_main_post!=null){
            postService.addReadingQuantity(id);
        }
        model.addAttribute("bl_main_post",bl_main_post);
        return "/content/blogcontent";
    }
}
